// 会员档案
import {
  trim, compact, get, isEmpty
} from 'lodash';
import { DataTypes, Model, UUIDV4 } from 'sequelize';
import { MySqlModel, getSequelize } from '../db';

class OpenUsers extends MySqlModel {

}

OpenUsers.init({
  id: {
    type: DataTypes.UUID, unique: 'id', allowNull: false, defaultValue: UUIDV4, validate: { isUUID: 4 }, primaryKey: true, comment: '主键'
  },
  hotel_id: {
    type: DataTypes.UUID, allowNull: false, validate: { isUUID: 4 }, comment: '主体'
  },
  appid: {
    type: DataTypes.STRING(50), allowNull: false, comment: '公众号的唯一标识'
  },
  mobile: { // 验证码绑定openid后即可自动关联档案, 档案关联会员卡
    type: DataTypes.STRING(50), allowNull: true, comment: '手机号'
  },

  /* 微信信息 */
  avatar: {
    type: DataTypes.STRING(200), defaultValue: null, comment: '微信头像'
  },
  country: { type: DataTypes.STRING(50), defaultValue: null, comment: '微信国家' },
  province: { type: DataTypes.STRING(50), defaultValue: null, comment: '微信省份' },
  city: { type: DataTypes.STRING(50), defaultValue: null, comment: '微信城市' },
  gender: { type: DataTypes.INTEGER, defaultValue: 0, comment: '0 未知, 1 男性, 2 女性' },
  language: { type: DataTypes.STRING(50), defaultValue: null, comment: '微信语言' },
  nickname: { type: DataTypes.STRING(50), defaultValue: null, comment: '微信昵称' },
  session_key: { type: DataTypes.STRING(120), allowNull: true, comment: '会话密钥' },
  openid: { type: DataTypes.STRING(50), allowNull: false, comment: '用户唯一标识' },
  unionid: {
    type: DataTypes.STRING(50), allowNull: true, defaultValue: null, comment: '用户统一标识（针对一个微信开放平台账号下的应用，同一用户的 unionid 是唯一的），只有当scope为"snsapi_userinfo"时返回'
  },
  /* 微信信息 */
  created_at: {
    type: DataTypes.DATE, allowNull: false, comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE, allowNull: false, comment: '更新时间'
  },
  version: {
    type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '版本控制'
  }
}, {
  sequelize: getSequelize(),
  tableName: 'open_user',
  comment: '微信用户信息',
  indexes: [
    { fields: ['appid', 'openid'], unique: true }
  ]
});

// https://sequelize.org/api/v6/class/src/model.js~model#static-method-hasMany

export default OpenUsers;
